package test

import xsd4gorm.Xsd4Gorminator
import xsd4gorm.model.Domain
import xsd4gorm.gen.ClassSourceGenerator


public class TestConstraints extends GroovyTestCase{

    Xsd4Gorminator gorminator
    Domain domain
    def file1 = "resources/constraints.xsd"


    protected void setUp(){
        gorminator = new Xsd4Gorminator(file1)
        domain = gorminator.generate()
    }

    void testFacets(){

        def expectedConstraints = [
                "[matches:'\\d{3}-[A-Z]{2}']",     /*pattern*/
                "[size:6]",                        /*length*/
                "[minSize:10000, maxSize:99999]",  /* max and min Inclusive*/
                "[minSize:10001, maxSize:99998]",  /* max and min Exclusive*/
                "[inList:['AK', 'AL', 'AR']]",     /* enumeration */
                "[matches:'\\d{3}-[A-Z]{2}']"]     /* pattern in attribute */

        domain.classes.each {domainClass ->
            println new ClassSourceGenerator(domainClass).generate()
        }

        domain.classes.each {domainClass ->
            println domainClass.getName()
            domainClass.getTypes().eachWithIndex {type, i ->
                println type.constraints
                println expectedConstraints[i]
                println '====='
                assert type.constraints.toString() == expectedConstraints[i].toString()
            }
            // assert expectedClassNames[i] == domainClass.getName()
        }
    }
}